package business.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import vo.Source;
import business.SourceService;
import dao.SourceCategoryDAO;
import dao.SourceDAO;

public class SourceServiceImpl implements SourceService {

	private SourceDAO sourceDao;
	private SourceCategoryDAO sourceCategoryDao;

	public List<Source> getAllSources() {
		return sourceDao.findAll();
	}

	public List<Source> getByName(int start, int pageSize, String name) {
		return sourceDao.findByName(start, pageSize, name);
	}

	public List<Source> getByType(int start, int pageSize, String type) {
		return sourceDao.findByType(start, pageSize, type);
	}

	public List<Source> getByNameType(int start, int pageSize, String name, String type) {
		return sourceDao.findByNameType(start, pageSize, name, type);
	}

	public List<Source> getByCategoryId(long categoryId) {
		return sourceDao.findByCategoryId(categoryId);
	}

	public List<Source> getAllSources(int start, int pageSize) {
		return sourceDao.findAll(start, pageSize);
	}

	public long getTotalCount() {
		return sourceDao.findTotalCount();
	}

	public long getTotalCountByName(String name) {
		return sourceDao.findTotalCountByName(name);
	}

	public long getTotalCountByType(String type) {
		return sourceDao.findTotalCountByType(type);
	}

	public long getTotalCountByNameType(String name, String type) {
		return sourceDao.findTotalCountByNameType(name, type);
	}

	@Required
	public void setSourceDao(SourceDAO sourceDao) {
		this.sourceDao = sourceDao;
	}

	@Transactional
	public void addSource(Source source) {
		sourceDao.create(source);
	}

	@Transactional
	public Source getById(long id) {
		return sourceDao.getById(id);
	}

	public Source getByEntry(String entry) {
		return sourceDao.getByEntry(entry);
	}
	@Transactional
	public void update(long id) {
		sourceDao.update(id);
	}

	@Transactional
	public void delete(long id) {
		sourceDao.delete(id);
	}

	public void setSourceCategoryDao(SourceCategoryDAO sourceCategoryDao) {
		this.sourceCategoryDao = sourceCategoryDao;
	}

}